package com.lineage.data.item_etcitem.add;

import com.lineage.config.Configtf;
import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_CloseList;
import com.lineage.server.serverpackets.S_HPUpdate;
import com.lineage.server.serverpackets.S_MPUpdate;
import com.lineage.server.serverpackets.S_OwnCharStatus2;
import com.lineage.server.serverpackets.S_SPMR;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class TfRe extends ItemExecutor {
  private static final Log _log = LogFactory.getLog(TfRe.class);
  
  public static ItemExecutor get() {
    return new TfRe();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    if (item == null)
      return; 
    if (pc == null)
      return; 
    if (!pc.getInventory().checkItem(Configtf.retfitem, Configtf.retfitemcount)) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage(Configtf.msg0));
      return;
    } 
    if (pc.get_other2().get_TfCount() > 0) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("请先将天赋点数点完"));
      return;
    } 
    pc.getInventory().consumeItem(Configtf.retfitem, Configtf.retfitemcount);
    pc.getInventory().removeItem(item, 1L);
    int SkillCount = pc.get_other2().get_Str() + pc.get_other2().get_Dex() + pc.get_other2().get_Dex() + 
      pc.get_other2().get_Attack() + pc.get_other2().get_BowAttack() + pc.get_other2().get_Hp() + 
      pc.get_other2().get_Mp() + pc.get_other2().get_ReductionDmg() + pc.get_other2().get_Sp() + 
      pc.get_other2().get_Mr();
    pc.get_other2().set_TfCount(SkillCount);
    pc.addDmgup(-pc.get_other2().get_Attack());
    pc.addBowDmgup(-pc.get_other2().get_BowAttack());
    pc.addSp(-pc.get_other2().get_Sp());
    pc.addStr(-pc.get_other2().get_Str());
    pc.addDex(-pc.get_other2().get_Dex());
    pc.addInt(-pc.get_other2().get_Int());
    pc.addMaxHp(-pc.get_other2().get_Hp());
    pc.addMaxMp(-pc.get_other2().get_Mp());
    pc.addMr(-pc.get_other2().get_Mr());
    pc.addother_ReductionDmg(-pc.get_other2().get_ReductionDmg());
    pc.get_other2().set_TfCount(pc.get_other2().get_TfCount1());
    pc.get_other2().set_Str(0);
    pc.get_other2().set_Dex(0);
    pc.get_other2().set_Int(0);
    pc.get_other2().set_Attack(0);
    pc.get_other2().set_BowAttack(0);
    pc.get_other2().set_Hp(0);
    pc.get_other2().set_Mp(0);
    pc.get_other2().set_ReductionDmg(0);
    pc.get_other2().set_Sp(0);
    pc.get_other2().set_Mr(0);
    pc.get_other2().set_TfCount1(0);
    pc.sendPackets((ServerBasePacket)new S_SystemMessage("天赋能力已还原"));
    pc.sendPackets((ServerBasePacket)new S_SPMR(pc));
    pc.sendPackets((ServerBasePacket)new S_MPUpdate(pc.getCurrentMp(), pc.getMaxMp()));
    pc.sendPackets((ServerBasePacket)new S_HPUpdate(pc.getCurrentHp(), pc.getMaxHp()));
    pc.sendPackets((ServerBasePacket)new S_OwnCharStatus2(pc));
    pc.sendPackets((ServerBasePacket)new S_CloseList(pc.getId()));
  }
}
